<!DOCTYPE html>


<html lang="en">
  

    <head>
      <meta charset="utf-8" />
        
      <meta name="description" content="時光的个人博客" />
      
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1"
      />
	  <meta name="referrer" content="no-referrer" />

      <title>定制化代码生成项目_day2 |  時光</title>
  <meta name="generator" content="hexo-theme-ayer">
      
      <link rel="shortcut icon" href="/favicon.ico" />
       
<link rel="stylesheet" href="/dist/main.css">

      
<link rel="stylesheet" href="/css/fonts/remixicon.css">

      
<link rel="stylesheet" href="/css/custom.css">
 
      <script src="https://cdn.staticfile.org/pace/1.2.4/pace.min.js"></script>
       
 

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bulma@5.0.1/bulma.min.css"
      />
      <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>

      <!-- mermaid -->
      
      <style>
        .swal2-styled.swal2-confirm {
          font-size: 1.6rem;
        }
      </style>
    <link rel="alternate" href="/atom.xml" title="時光" type="application/atom+xml">
</head>
  </html>
</html>


<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-定制化代码生成项目-day2"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  定制化代码生成项目_day2
</h1>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/11/14/%E5%AE%9A%E5%88%B6%E5%8C%96%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90%E9%A1%B9%E7%9B%AE-day2/" class="article-date">
  <time datetime="2023-11-14T04:59:20.000Z" itemprop="datePublished">2023-11-14</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E9%A1%B9%E7%9B%AE%E7%AC%94%E8%AE%B0/">项目笔记</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">1.4k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">5 min</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="前情回顾"><a href="#前情回顾" class="headerlink" title="前情回顾"></a>前情回顾</h2><p>在上一期教程中，我们已经了解了整个定制化代码生成项目的需求背景、三大阶段、技术选型，并且通过对三个阶段分别进行分析，学习了各阶段的业务流程、实现思路和待解决的问题。</p>
<p>从本节教程开始，鱼皮会依次带大家完成三个阶段的开发实现，解决之前提到的各种问题。</p>
<h2 id="本节重点"><a href="#本节重点" class="headerlink" title="本节重点"></a>本节重点</h2><p>本节教程属于项目的第一阶段 —— 开发本地代码生成器。</p>
<p>重点内容：</p>
<ol>
<li>完成项目的初始化</li>
<li>静态文件生成</li>
<li>动态文件代码生成</li>
<li>FreeMarker 模板引擎入门及实战</li>
<li>动静结合 - ACM 示例项目模板代码生成</li>
</ol>
<h2 id="一、项目初始化"><a href="#一、项目初始化" class="headerlink" title="一、项目初始化"></a>一、项目初始化</h2><h3 id="1、初始化根目录"><a href="#1、初始化根目录" class="headerlink" title="1、初始化根目录"></a>1、初始化根目录</h3><p>由于我们的项目包含多个阶段，本质上是多个项目，所以为了统一管理整个项目，我们创建一个干净的<code> template-generator</code> 空文件夹，作为整个项目的根目录，后续各阶段的项目和目录都放到它之下。<br>这样做还有一个好处，就是让不同项目模块可以用 相对路径 寻找文件，便于整个项目的开源共享。<br>建议大家养成习惯，使用 Git 来管理项目。如果使用 IDEA 开发工具来创建新项目，可以直接勾选 Create Git repository ，工具会自动帮你初始化项目为 Git 仓库。</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231114130738168-1948313359.png" alt="image-20231114130738776"></p>
<p>当然，也可以进入项目根目录，执行 <code>git init</code> 命令创建 Git 仓库。</p>
<h3 id="2、创建忽略文件"><a href="#2、创建忽略文件" class="headerlink" title="2、创建忽略文件"></a>2、创建忽略文件</h3><p>创建好新项目后，使用 IDEA 开发工具打开项目，进入底部的 <code>Git </code>标签，会发现很多和项目无关的 IDEA 自动生成的工程文件被添加到了 Git 托管。</p>
<p>新初始化的项目没有提交记录，可以点击<code>Commit local changes</code> </p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231114131047442-100033204.png" alt="image-20231114131048121"></p>
<p>或者直接点击侧边栏<code>Commit</code>选项</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231114131347111-1875962650.png" alt="image-20231114131347901"></p>
<p>我们不希望提交这些没有意义的文件，所以需要使用 <code>.gitignore </code>文件来忽略这些文件，不让它们被 Git 托管。<br>那么如何编写<code> .gitignore</code> 文件呢？</p>
<p>其实这个忽略文件没必要自己写，我们可以在 IDEA 的 Settings &#x3D;&gt; Plugins 中搜索 <code>.ignore</code> 插件并安装：</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231114132121843-1779918185.png" alt="image-20231114132122606"></p>
<p>如果网络或其他原因导致搜索不出来，可以到<a target="_blank" rel="noopener" href="https://plugins.jetbrains.com/plugin/7495--ignore">官方插件市场</a>下载到本地采用从磁盘安装的方式</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231114132339542-1331521183.png" alt="image-20231114132340104"></p>
<p>然后在项目根目录处选中右键，使用 .ignore 插件创建 .gitignore 文件：</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231114133121968-2061017438.png" alt="image-20231114133122575"></p>
<p>可以在搜索框中搜索需要的忽略类型，比如<code>JetBrains</code>、<code>Java</code>、<code>Maven</code>等</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231114133348523-2117359186.png" alt="image-20231114133349201"></p>
<p>IDEA询问是否将该文件添加到版本库，添加即可</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231114133714418-843339042.png" alt="image-20231114133715188"></p>
<p>也可以添加一些自定义忽略文件或目录</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231120221518424-682582666.png" alt="image-20231120221517691"></p>
<p>但是，即使有些文件已经添加到了<code> .gitignore</code> 文件中，在 IDEA 中显示的还是绿色（已被 Git 托管）状态</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231120222021476-30701430.png" alt="image-20231120222021082"></p>
<p>这是因为这些文件已经被 Git 跟踪。而<code>.gitignore</code> 文件仅影响未跟踪的文件</p>
<p>如果文件已经被 Git 跟踪，那么 <code>.gitignore</code> 文件对它们没有影响<br>所以我们需要打开终端，在项目根目录下执行如下命令，取消 Git 跟踪</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">rm</span> -rf --cached .</span><br></pre></td></tr></table></figure>

<p>执行效果如下</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231120222151167-1504539761.png" alt="image-20231120222150842"></p>
<p>将文件重新添加到暂存区、例如将刚才创建的<code>.gitignore</code>添加到暂存区</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231120222407576-1192476449.png" alt="image-20231120222407201"></p>
<h3 id="3、创建-Demo-示例代码工程"><a href="#3、创建-Demo-示例代码工程" class="headerlink" title="3、创建 Demo 示例代码工程"></a>3、创建 Demo 示例代码工程</h3><p>为了制作代码生成器，我们需要一些示例模板代码，后续会基于这些模板代码来定制生成。<br>比如第一阶段，我们会用到一套鱼皮提前编写好的 ACM 示例模板代码，从而制作定制化 ACM 模板代码生成器</p>
<p>在第二阶段，我们会用到一套 Spring Boot 初始化项目模板。<br>让我们新建一个 <code>shiguang-generator-demo-projects</code> 目录，统一存放所有的示例代码，然后将鱼皮准备的 ACM 模板项目（acm-template）复制到该目录下。</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231120223611034-832583174.png" alt="image-20231120223610559"></p>
<h4 id="ACM-示例代码模板介绍"><a href="#ACM-示例代码模板介绍" class="headerlink" title="ACM 示例代码模板介绍"></a>ACM 示例代码模板介绍</h4><p>鱼皮准备的 ACM 示例代码模板非常简单，只是一个干净的 Java 项目，没有使用 Maven 和任何第三方依赖<br>结构如下，核心组成是静态文件 <code>README.md</code> 和代码文件 <code>MainTemplate</code></p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231120223903675-2081076447.png" alt="image-20231120223902936"></p>
<p><code>README.md</code>内容如图，仅包含了简单的描述文本</p>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231120223952403-971394141.png" alt="image-20231120223952121"></p>
<p><code>MainTemplate.java</code> 是一段 ACM 示例输入代码，作用是计算并输出多数之和</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.shiguang.acm;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.Scanner;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * ACM 输入模板（多数之和）</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MainTemplate</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="type">Scanner</span> <span class="variable">scanner</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">while</span> (scanner.hasNext()) &#123;</span><br><span class="line">            <span class="comment">// 读取输入元素个数</span></span><br><span class="line">            <span class="type">int</span> <span class="variable">n</span> <span class="operator">=</span> scanner.nextInt();</span><br><span class="line"></span><br><span class="line">            <span class="comment">// 读取数组</span></span><br><span class="line">            <span class="type">int</span>[] arr = <span class="keyword">new</span> <span class="title class_">int</span>[n];</span><br><span class="line">            <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; n; i++) &#123;</span><br><span class="line">                arr[i] = scanner.nextInt();</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="comment">// 处理问题逻辑，根据需要进行输出</span></span><br><span class="line">            <span class="comment">// 示例：计算数组元素的和</span></span><br><span class="line">            <span class="type">int</span> <span class="variable">sum</span> <span class="operator">=</span> <span class="number">0</span>;</span><br><span class="line">            <span class="keyword">for</span> (<span class="type">int</span> num : arr) &#123;</span><br><span class="line">                sum += num;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            System.out.println(<span class="string">&quot;Sum: &quot;</span> + sum);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        scanner.close();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>在第一阶段的教程中，我们将改造这个 Java 代码文件，让它能同时支持多种不同的输入方式</p>
<h3 id="4、创建本地代码生成器项目"><a href="#4、创建本地代码生成器项目" class="headerlink" title="4、创建本地代码生成器项目"></a>4、创建本地代码生成器项目</h3><p>使用 IDEA 开发工具，在项目根目录中新建工程，创建 yuzi-generator-basic 项目。需要注意以下几点：</p>
<ol>
<li>项目存放位置在 <code>template_generator </code>根目录下</li>
<li>取消 Git 仓库勾选（因为已经在外层进行 Git 托管）</li>
<li>使用 Maven 管理项目</li>
<li>JDK 选择 1.8！不要追求新版本</li>
<li>高级设置中，指定 GroupId 和 ArtifactId</li>
</ol>
<p><img src="https://img2023.cnblogs.com/blog/2233039/202311/2233039-20231120224816678-1665314943.png" alt="image-20231120224815563"></p>
 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          Donate
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>Copyright： </strong>
          
          Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2023/11/14/%E5%AE%9A%E5%88%B6%E5%8C%96%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90%E9%A1%B9%E7%9B%AE-day2/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%AD%A6%E4%B9%A0/" rel="tag">学习</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E9%A1%B9%E7%9B%AE/" rel="tag">项目</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2023/11/14/E9%E5%AE%89%E8%A3%85%E6%89%8B%E5%86%8C/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            E9安装手册
          
        </div>
      </a>
    
    
      <a href="/2023/11/13/%E5%AE%9A%E5%88%B6%E5%8C%96%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90%E9%A1%B9%E7%9B%AE-day1/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">定制化代码生成项目_day1</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.staticfile.org/valine/1.4.16/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "dx3B54wOwhi75vxC2IAZagtg-gzGzoHsz",
    app_key: "m4k2fhnFa1iPI4vbofHqMY5X",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
   
  
   
    <script src="https://cdn.staticfile.org/twikoo/1.4.18/twikoo.all.min.js"></script>
    <div id="twikoo" class="twikoo"></div>
    <script>
        twikoo.init({
            envId: ""
        })
    </script>
 
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2023
        <i class="ri-heart-fill heart_icon"></i> Shiguang
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></span>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>    
    </main>
    <div class="float_btns">
      <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

    </div>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="時光"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-3.6.0.min.js"></script>
 
<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->
 
<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: ".tocbot",
    contentSelector: ".article-entry",
    headingSelector: "h1, h2, h3, h4, h5, h6",
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: "main",
    positionFixedSelector: ".tocbot",
    positionFixedClass: "is-position-fixed",
    fixedSidebarOffset: "auto",
  });
</script>

<script src="https://cdn.staticfile.org/jquery-modal/0.9.2/jquery.modal.min.js"></script>
<link
  rel="stylesheet"
  href="https://cdn.staticfile.org/jquery-modal/0.9.2/jquery.modal.min.css"
/>
<script src="https://cdn.staticfile.org/justifiedGallery/3.8.1/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->
 <!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.staticfile.org/photoswipe/4.1.3/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.staticfile.org/photoswipe/4.1.3/default-skin/default-skin.min.css">
<script src="https://cdn.staticfile.org/photoswipe/4.1.3/photoswipe.min.js"></script>
<script src="https://cdn.staticfile.org/photoswipe/4.1.3/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script> 
<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->
 
<script src="/js/busuanzi-2.3.pure.min.js"></script>
 
<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->
 
<link rel="stylesheet" href="/css/clipboard.css">
 <script src="https://cdn.staticfile.org/clipboard.js/2.0.10/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>
 
<!-- CanvasBackground -->

<script>
  if (window.mermaid) {
    mermaid.initialize({ theme: "forest" });
  }
</script>


    
    

  </div>
</body>

</html>